<!DOCTYPE html>
<html>

  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
      <!-- 增加 sweetalert -->
      <link rel="stylesheet" href="/static/sweetalert/sweetalert.css">
      <script src="/static/sweetalert/ions_alert.js"></script>
      <script src="/static/sweetalert/sweetalert.min.js"></script>
  </head>

  <body>
    <div class="x-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">上级权限</label>
                <div class="layui-input-inline"  style="width: 200px;">
                    <select  lay-filter="aihao" id="auth_parent_id">
                        <option value="0">--无--</option>
                        {{ range .auths }}
                            <option value="{{ .Id }}">{{ .AuthName }}</option>
                        {{ end }}
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">无上级权限请留空</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">权限名称</label>
                <div class="layui-input-inline" style="width:200px;">
                    <input type="text" lay-verify="title" placeholder="请输入权限名称" autocomplete="off" class="layui-input" id="auth_name">
                </div>
                <div class="layui-form-mid layui-word-aux">权限名称不能重复</div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">URL地址</label>
                <div class="layui-input-inline" style="width:200px;">
                    <input type="text" id="auth_url" lay-verify="title" placeholder="请输入URL地址" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">使用urlfor规则</div>
            </div>

           <!-- <div class="layui-form-item">
                <label class="layui-form-label">请求方法</label>
                <div class="layui-input-inline"  style="width: 200px;">
                    <select name="interest" lay-filter="aihao" name="role_method" id="role_method">
                        <option value="1">GET</option>
                        <option value="2">POST</option>
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">默认GET请求</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">参数列表</label>
                <div class="layui-input-inline" style="width:200px;">
                    <input type="text" id="role_arguments" name="role_arguments" lay-verify="title" placeholder="请输入参数列表" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">多个参数名之间用英文逗号隔开</div>
            </div>-->

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-block">
                    <textarea id="auth_desc" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-block">
                    <input name="is_active" id="is_active_1" type="radio" value="1" checked="checked" title="启用"/>
                    <input name="is_active" id="is_active_0" type="radio" value="0" title="停用"/>

                    <!--<input type="checkbox" id="is_active" name="is_active" lay-skin="switch" lay-text="启用|停用">-->
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">权重</label>
                <div class="layui-input-inline" style="width:200px;">
                    <input type="text" id="auth_weight" lay-verify="title" placeholder="请输入数字权重" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">权重只能为数字，值越大排序越前</div>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <div class="layui-footer" >
                        <button lay-filter="add" lay-submit class="layui-btn">立即提交</button>
                        <a href="" class="layui-btn layui-btn-primary">返回</a>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <script>
        $(function  () {
            layui.use('form', function () {
                var form = layui.form;
          //监听提交
          form.on('submit(add)', function(data){
              var auth_parent_id = document.getElementById("auth_parent_id").value;
              var auth_name = document.getElementById("auth_name").value;
              var auth_url = document.getElementById("auth_url").value;
              var auth_desc = document.getElementById("auth_desc").value;
              var is_active = $("input[name=is_delete]:checked").val();
              var auth_weight = document.getElementById("auth_weight").value;
                  $.ajax({
                      url : "{{ urlfor `AuthController.DoAdd` }}",
                      type :"POST",
                      data : {
                          "auth_parent_id" : auth_parent_id,
                          "auth_name" : auth_name,
                          "auth_url" : auth_url,
                          "auth_desc" : auth_desc,
                          "is_active" : is_active,
                          "auth_weight" : auth_weight
                      },
                      success:function (data){
                          var code = data["code"];
                          if (code == 200) {
                              ions_alert.alertSuccessToast(data["msg"]);
                              setTimeout(reload_list, 2000);
                          } else {
                              ions_alert.alertErrorToast(data["msg"]);
                              setTimeout(reload_list, 2000);
                          }
                      },
                      error:function (data){
                          ions_alert.alertErrorToast("添加数据失败");
                          setTimeout(reload_list, 2000);
                      }
                  })
          });
        });
     });
        function reload_list(){
            /* 获得frame索引 */
            var index = parent.layer.getFrameIndex(window.name);
            /* 关闭当前frame,关闭弹出小窗口 */
            parent.layer.close(index);
            window.location.href = "{{ urlfor `AuthController.List` }}"
        }
    </script>
    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
  </body>

</html>